/**
 *  @file SDLWindow.cpp
 *
 *  @date 18-nov-2009
 *  @author Ives van der Flaas
 */

#include <SDL.h>
#include <SDL_ttf.h>
#include "SDLWindow.h"
#include "SDLException.h"
#include "SDLAudioManager.h"


si_sdl::SDLWindow::SDLWindow(std::string titleBar)
{
	if(SDL_Init(SDL_INIT_EVERYTHING))
	{
		throw SDLException("Cannot initialise SDL. Make sure you're not running from console?\n");
	}


	if (TTF_Init() == -1)
	{
		throw SDLException(
					std::string("Cannot initialise SDL_ttf: ")
				+ 	std::string(TTF_GetError()));
	}

	// Initialise SDL Mixer by calling audio manager
	SDLAudioManager::get();

    const int width = 600;
    const int height = 450;
    const int bpp = 32;

    // Set the Program icon...
   // SDL_WM_SetIcon(SDL_LoadBMP("images/icon.bmp"), NULL);
    fScreen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE|SDL_RESIZABLE);

    if(fScreen == 0)
    {
    	throw SDLException("Cannot SetVideoMode.\n");
    }

    SDL_WM_SetCaption(titleBar.c_str(), titleBar.c_str());

}

si_sdl::SDLWindow::~SDLWindow()
{
	// Screen surface is freed by SDL_Quit()!!!
	SDL_Quit();


}

void si_sdl::SDLWindow::flip() throw (si_sdl::SDLException)
{
	if( SDL_Flip(fScreen) == -1)
		throw si_sdl::SDLException("Cannot flip screen. ");
}







